<template>
  <view class="content">
    <u-navbar title="信息" :is-back="true" :background="background" titleColor="#fff">
    	<!-- 添加返回按钮 -->
    	<u-icon slot="left" name="arrow-left" color="#ffffff" @click="goBack"></u-icon>
    </u-navbar>
    <view class="messages">
      <view class="message-item" v-for="(item, index) in messages" :key="index">
        <view class="message-content">
          <text class="message-text">{{ item.text }}</text>
          <text class="message-time">{{ item.time }}</text>
        </view>
      </view>
    </view>
  </view>
</template>
<script>
export default {
  data() {
    return {
		background: {
			'background-image': 'linear-gradient(45deg, rgb(28, 187, 180), rgb(141, 198, 63))'
		},
      messages: [
        {
          text: '用户注册成功',
          time: ''
        },
        {
          text: '用户登录成功',
          time: ''
        }
      ]
    };
  },
  methods: {
    getFormattedTime(timeStamp) {
      if (!timeStamp) return '';
      const date = new Date(timeStamp);
      return date.toLocaleString();
    },
    goBack() {
      // 导航回上一页面
      wx.navigateBack({
        delta: 1 // 返回的页面数，如果 delta 大于现有页面数，则返回到首页
      });
    }
  },
  mounted() {
    let userInfo = localStorage.getItem('userinfo');
    const u = JSON.parse(userInfo).successMessage;
    this.messages = [
      {
        text: '用户注册成功',
        time: this.getFormattedTime(u.create_time)
      },
      {
        text: '用户登录成功',
        time: this.getFormattedTime(u.update_time)
      }
    ];
  }
}
</script>
<style>
.content {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
  background-color: #f7f7f7;
  position: relative; /* 添加相对定位 */
}

.back-button {
  position: absolute;
  top: 20px;
  left: 20px;
}

.back-icon {
  font-size: 24px; /* 设置箭头图标的大小 */
  color: #333; /* 设置箭头图标的颜色 */
}

.messages {
  margin-top: 30px;
  width: 100%;
  max-width: 600px; /* 限制消息列表的最大宽度 */
}

.message-item {
  margin-bottom: 20px;
}

.message-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px;
  background-color: #ffffff;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
}

.message-content:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.message-text {
  font-size: 16px;
  color: #333;
  font-weight: 500;
}

.message-time {
  font-size: 14px;
  color: #666;
}
</style>